package com.cskaoyan.controller;

import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.vo.WxFootprintVo;
import com.cskaoyan.mapper.CskaoyanmallUserMapper;
import com.cskaoyan.service.WxFootprintService;
import com.cskaoyan.utils.QueryUserIdByUserNameUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("wx/footprint/")
public class WxFootprintController {

    @Autowired
    CskaoyanmallUserMapper userMapper;

    @Autowired
    WxFootprintService footprintService;

    /**
     * 查询足迹
     */
    @GetMapping("list")
    public BaseRespVo listFoot(Integer page, Integer size) {

        Integer userId = QueryUserIdByUserNameUtils.queryName(userMapper);

        WxFootprintVo footprintVo = footprintService.queryFoot(page, size, userId);

        return BaseRespVo.success(footprintVo);
    }

    /**
     * 删除足迹
     */
    @PostMapping("delete")
    public BaseRespVo deleteFoot(@RequestBody Map<String,Integer> map){

        Integer userId = QueryUserIdByUserNameUtils.queryName(userMapper);

        Integer id = map.get("id");

        footprintService.deleteFoot(id, userId);

        return BaseRespVo.success();
    }
}
